from tkinter import Tk, Canvas, Frame, BOTH

class Application(Frame):
  
    def __init__(self, parent):
        Frame.__init__(self, parent)   
         
        self.parent = parent
        self.leftX=50
        self.leftY=50
        self.widthX=20
        self.widthY=20
        self.canvas=Canvas(self) 
        self.parent.title("Snake")      
        self.initUI()
		
    def initUI(self):
              
        self.pack(fill=BOTH, expand=1)
        self.canvas.bind_all("<Key>", self.onPressed)
        self.canvas.create_rectangle(self.leftX, self.leftY, self.leftX+self.widthX, self.leftY+self.widthY, 
            outline="#fb0", fill="#fb0")   
        self.canvas.pack(fill=BOTH, expand=1)

    def onPressed(self, e):
        key = e.keysym
        if key == "a":
            pass
        if key == "d":
            pass
        if key == "w":
            pass
        if key == "s":
            pass
        
        self.canvas.delete("all")
        self.initUI()

root = Tk()
ex = Application(root)
root.geometry("400x400+300+100")
root.mainloop()
